package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingGradeDto;
import com.zzyl.service.NursingGradeService;
import com.zzyl.vo.NursingGradeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

/**
 * @param
 * @return
 */
@Api(tags = "护理等级相关接口")
@RestController
@RequestMapping("/nursingLevel")
public class NursingGradeController {
    @Autowired
    private NursingGradeService nursingGradeService;

    //查询所有护理等级
    @ApiOperation(value = "查询所有护理等级")
    @GetMapping("/listAll")
    public ResponseResult selectAllNursingGrade() {
        List<NursingGradeVo> nursingGradeVo = nursingGradeService.selectAllNursingGrade();
        return success(nursingGradeVo);
    }

    //新增
    @ApiOperation(value = "新增护理等级")
    @PostMapping("/insert")
    public ResponseResult insertNursingGrade(@RequestBody NursingGradeDto nursingGradeDto) {
        nursingGradeService.insertNursingGrade(nursingGradeDto);
        return success();
    }

    //分页条件查询
    @ApiOperation(value = "分页条件查询")
    @GetMapping("listByPage")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "护理等级名称", name = "name", dataType = "string"),
            @ApiImplicitParam(value = "启用状态", name = "status", dataType = "string"),
            @ApiImplicitParam(value = "页码", name = "pageNum", required = true, dataType = "int"),
            @ApiImplicitParam(value = "每页显示条数", name = "pageSize", required = true, dataType = "int")})
    public ResponseResult selectByPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageResponse page = nursingGradeService.selectByPage(name, pageNum, pageSize, status);
        return success(page);
    }

    //查询回显
    @ApiOperation(value = "根据id查询回显")
    @GetMapping("/{id}")
    public ResponseResult selectById(@PathVariable Long id) {
        NursingGradeVo nursingGradeVo = nursingGradeService.selectById(id);
        return success(nursingGradeVo);
    }

    //修改
    @ApiOperation(value = "修改护理等级")
    @PutMapping("/update")
    public ResponseResult updateNursingGrade(@RequestBody NursingGradeDto nursingGradeDto) {
        nursingGradeService.updateNursingGrade(nursingGradeDto);
        return success();
    }

    //删除
    @ApiOperation(value = "删除护理等级")
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteNursingPlan(@PathVariable Long id) {
        nursingGradeService.deleteNursingPlan(id);
        return success();
    }

    //启用/禁用
    @ApiOperation(value = "启用/禁用护理等级")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult idStatusNursigGrade(@PathVariable Long id, @PathVariable Integer status) {
        nursingGradeService.idStatusNursigGrade(id,status);
        return success();
    }


}
